package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/5/5.
 */
@RestController
@RequestMapping("/ComputeController")
public class ComputeController {

    @Autowired
    private DiscoveryClient client;

    @RequestMapping("/add")
    public String add(HttpServletRequest request){
        ServiceInstance instance = client.getLocalServiceInstance();
        String a = request.getParameter("a");
        String b = request.getParameter("b");
        System.out.println(a + b);
        System.out.println("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + a + b);
        return a + b;
    }
}
